package com.avic.rong.adapter.show;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.bean.show_bean.AchieveBean;
import com.bumptech.glide.Glide;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by TSJ-2018-0492 on 2019/9/19.
 */

public class AchrecomAdapter extends RecyclerView.Adapter<AchrecomAdapter.AchrecimViewHolder> {
    private Context context;
    private List<AchieveBean.RecomSListBean> recomSListBeans;

    public void setRecomSListBeans(List<AchieveBean.RecomSListBean> recomSListBeans) {
        this.recomSListBeans = recomSListBeans;
        notifyDataSetChanged();
    }

    public AchrecomAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public AchrecomAdapter.AchrecimViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(context).inflate(R.layout.achieve_recomgy_item, viewGroup, false);
        return new AchrecimViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull AchrecomAdapter.AchrecimViewHolder achrecimViewHolder, int i) {
        if (recomSListBeans != null) {
            AchieveBean.RecomSListBean recomSListBean = recomSListBeans.get(i);
            if (recomSListBean.getTargetName() != null) {
                achrecimViewHolder.acheve_tjgy_title.setText(recomSListBean.getTargetName() + "");
            }
            if (recomSListBean.getPrice() != null) {
                achrecimViewHolder.acheve_tjgy_price.setText("参考价格:" + recomSListBean.getPrice() + "");
            }
            if (recomSListBean.getTargetImg() != null) {
                Glide.with(context).load(recomSListBean.getTargetImg()).into(achrecimViewHolder.achieve_tjgy_image);
            }
            achrecimViewHolder.achieve_tjgy_status.setText("个人");

        }
    }

    @Override
    public int getItemCount() {
        if (recomSListBeans != null) {
            return recomSListBeans.size();
        }
        return 0;
    }

    public class AchrecimViewHolder extends RecyclerView.ViewHolder {

        private TextView achieve_tjgy_status;
        private TextView acheve_tjgy_price;
        private TextView acheve_tjgy_title;
        private ImageView achieve_tjgy_image;

        public AchrecimViewHolder(@NonNull View itemView) {
            super(itemView);
            achieve_tjgy_status = itemView.findViewById(R.id.achieve_tjgy_status);
            acheve_tjgy_price = itemView.findViewById(R.id.acheve_tjgy_price);
            acheve_tjgy_title = itemView.findViewById(R.id.acheve_tjgy_title);
            achieve_tjgy_image = itemView.findViewById(R.id.achieve_tjgy_image);
        }
    }
}
